<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        const input=`6 5
0 0 0 -1 0 0 0 0 0 0 0 0 -1 4 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0
1 4`
        let spl=input.split('\n').map(v=>v.trim())
        let [m,n]=spl[0].split(' ').map(v=>parseInt(v))
        let [x,y]=spl[2].split(' ').map(v=>parseInt(v))
        let array=new Array(m)
        let max=-1
        let [max_i,max_j]=[0,0]
        for(let i=0;i<m;i++){    
            array[i]=spl[1].split(' ').slice(i*n,(i+1)*n).map((v,j)=>{
                if(v>0){
                    max=v;
                    [max_i,max_j]=[i,j];
                }
               return parseInt(v)
            })
        }
        let list=[[max_i,max_j]]
        
        while(list.length>0){
            let [x,y]=list.shift()
            let value=array[x][y]
            if(value>1){
                if(y+1<n&&array[x][y+1]===0){
                    array[x][y+1]=value-1
                    list.push([x,y+1])
                }
                if(y-1>=0&&array[x][y-1]===0){
                    array[x][y-1]=value-1
                    list.push([x,y-1])
                }
                if(x+1<m&&array[x+1][y]===0){
                    array[x+1][y]=value-1
                    list.push([x+1,y])
                }
                if(x-1>=0&&array[x-1][y]===0){
                    array[x-1][y]=value-1
                    list.push([x-1,y])
                }


            }
            
        }

        console.log(...array);
        console.log(max,[max_i,max_j]);
        


    </script>
</body>
</html>
